[Android] accessing another Activity's preferences
        Posted  
        
            by 
                Raffaele
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Raffaele
        
        
        
        Published on 2011-01-06T20:51:36Z
        Indexed on 
            2011/01/06
            20:54 UTC
        
        
        Read the original article
        Hit count: 353
        
android
|android-preferences
I have a Login Activity which stores credentials in its own SharedPreferences; then I added two getters for reading them, something like
public String getUsername() {
  return getPreferences(MODE_PRIVATE).getString("#username", null);
}
but this throws a NPE when I call it like this
String mUser = (new Login()).getUsername();
It seems that the Activity cannot read its preferences after a simple contructor call, as if it were in some uncompleted state. I read lots of related topics, but wasn't able to find a solution. Basically, I need to share these credentials among activities in my application
© Stack Overflow or respective owner